//
//  WeiboAnnotationView.m
//  Custom_Weibo
//
//  Created by LEO on 12/20/15.
//  Copyright © 2015 Leo_Lei. All rights reserved.
//

#import "WeiboAnnotationView.h"

@implementation WeiboAnnotationView {
    UIImageView *_headImageView;
    UILabel *_textLabel;
}

#pragma mark - INITIALIZATION_METHODS
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.bounds = CGRectMake(0, 0, 100, 40);
        [self addAnnotationView];
    }
    return self;
}

#pragma mark - SHOW_CUSTOM_VIEW
- (void)addAnnotationView {
    CGRect headerFrame = CGRectMake(0, 0, 40, 40);
    _headImageView = [[UIImageView alloc] initWithFrame:headerFrame];
    [self addSubview:_headImageView];
    
    CGRect textFrame = CGRectMake(40, 0, 100, 40);
    _textLabel = [[UILabel alloc] initWithFrame:textFrame];
    _textLabel.backgroundColor = [UIColor lightGrayColor];
    _textLabel.font = [UIFont systemFontOfSize:13];
    _textLabel.numberOfLines = 0;
    [self addSubview:_textLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    WeiboAnnotation *annotation = self.annotation;
    WeiboModel *model = annotation.weiboModel;
    
    NSString *urlString = model.userModel.profile_image_url;
    
    //  Set the image and the detail text.
    NSURL *url = [NSURL URLWithString:urlString];
    UIImage *placeHolderImage = [UIImage imageNamed:@"icon"];
    [_headImageView sd_setImageWithURL:url placeholderImage:placeHolderImage];
    _textLabel.text = model.text;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
